// pages/qiye_jieshao/qiye_jieshao.js
const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');
Page({
  data: {
    navIndex1: -1,
    list: [],
    p: 1,
    userinfo: [],
    from: ''
  },

  onLoad(options) {
    this.setData({
      from: options.from,
      navIndex1: options.state,
      userinfo: wx.getStorageSync('user')
    });
    wx.setNavigationBarTitle({
      title: '我的订单'
    });
    this.getinfo();
  },

  copynum(str) {
    wx.setClipboardData({
      data: str,
      success: function () {
        wx.showToast({
          title: '复制成功',
          icon: 'none'
        });
      }
    });
  },

  navtab1(e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      p: 1,
      navIndex1: index,
      list: []
    });
    this.getinfo();
  },

  getinfo() {
    const that = this;
    const url = this.data.from === 'sp' ? app.data.apiurl+'mallshop/getMyOrder' : app.data.rooturl+'order/getMyOrder';
    util.httpRrquest(url, 'GET', { type: that.data.navIndex1,
        page: that.data.p,
        logType: 2})
    .then(function (response) {
        var res = response.data.data;
        that.setData({
          list: that.data.list.concat(res.orderlist),
          p: that.data.p + 1
        });
    }, function (error) {
        console.log(error);
    });
  },

  onReachBottom() {
    this.getinfo();
  },

  details(e) {
    const id = e.currentTarget.dataset.id;
    // 跳转到订单详情页
    wx.navigateTo({
      url: '/pages/orderDetail/orderDetail?id=' + id
    });
  }
});